﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using Research.BLL;

namespace Research.Web
{
    public partial class PrjMainShow : System.Web.UI.Page
    {
        readonly RprjMainBll _bllMain = new RprjMainBll();

        protected void Page_Load(object sender, EventArgs e)
        {
            BindGrid();
            btnAdd.OnClientClick += windowRprjDetails.GetShowReference("RprjDetails.aspx?Type=Add", "添加");
            btnUpdate.OnClientClick = gridPrjShow.GetNoSelectionAlertInTopReference("没有选中修改项!");

        }

        private void BindGrid()
        {
            int totalRecord;
            gridPrjShow.DataSource = _bllMain.ShowPageRprjMain(gridPrjShow.PageIndex + 1, out totalRecord);
            gridPrjShow.RecordCount = totalRecord;
            gridPrjShow.PageSize = 20;
            gridPrjShow.DataBind();
        }

        protected void gridPrjShow_PageIndexChange(object sender, ExtAspNet.GridPageEventArgs e)
        {
            gridPrjShow.PageIndex = e.NewPageIndex;
            BindGrid();
        }

        protected void gridPrjShow_Sort(object sender, ExtAspNet.GridSortEventArgs e)
        {
            int totalRecord;
            DataTable table = _bllMain.ShowPageRprjMain(gridPrjShow.PageIndex, out totalRecord).Tables[0];

            DataView view1 = table.DefaultView;
            view1.Sort = String.Format("{0} {1}", e.SortField, e.SortDirection);

            gridPrjShow.DataSource = view1;
            gridPrjShow.DataBind();
        }

        protected void gridPrjShow_RowCommand(object sender, ExtAspNet.GridCommandEventArgs e)
        {
            if (e.CommandName=="aaa")
                ExtAspNet.Alert.Show("aaasdsada");
        }

        protected void gridPrjShow_PreRowDataBound(object sender, ExtAspNet.GridPreRowEventArgs e)
        {
            var row = e.DataItem as DataRowView;
            var winHasFoundData = (ExtAspNet.WindowField)gridPrjShow.FindColumn("winHasFoundData");
            if ((int)row["HasFoundData"] == 1)
                winHasFoundData.Icon = ExtAspNet.Icon.Accept;
            else
                winHasFoundData.Icon = ExtAspNet.Icon.Delete;

            var winHasProcessData = (ExtAspNet.WindowField)gridPrjShow.FindColumn("winHasProcessData");
            if ((int)row["HasProcessData"] == 1)
                winHasProcessData.Icon = ExtAspNet.Icon.Accept;
            else
                winHasProcessData.Icon = ExtAspNet.Icon.Delete;

            var winHasFinishData = (ExtAspNet.WindowField)gridPrjShow.FindColumn("winHasFinishData");
            if ((int)row["HasFinishData"] == 1)
                winHasFinishData.Icon = ExtAspNet.Icon.Accept;
            else
                winHasFinishData.Icon = ExtAspNet.Icon.Delete;
        }

        protected void btnFilter_Click(object sender, EventArgs e)
        {
            
        }

        protected void gridPrjShow_RowClick(object sender, ExtAspNet.GridRowClickEventArgs e)
        {
            btnUpdate.OnClientClick += windowRprjDetails.GetShowReference("RprjDetails.aspx?Type=Update&rPrjID=" + gridPrjShow.Rows[e.RowIndex].DataKeys[0], "修改");
        }

        protected void windowData_Close(object sender, ExtAspNet.WindowCloseEventArgs e)
        {

        }




    }
}